
#include "Particle.hpp"

#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <ctime>
#include <iostream>

static int hwin = 0;

System ps;

void frametimer (int value)
{
	glutPostRedisplay ();
	glutTimerFunc (10, frametimer, 0);
}

void display ()
{
	glClear (GL_COLOR_BUFFER_BIT);

	glPushMatrix ();
//	glTranslatef (ps.center [0], ps.center [1], 0);

	ps.update_all (0.001f);
	
	ps.draw_all ();

	glPopMatrix ();

	glutSwapBuffers ();
	
//	glutPostRedisplay ();
}

void keyboard (unsigned char _key, int _x, int _y)
{
	if (_key == 'q')
	{
		glutDestroyWindow (hwin);
		exit (0);
	}
	if (_key == ' ')
	{
		ps.emit <SwarmParticle> (10);
	}
}

int main (int _argc, char **_argv)
{
	srand (time (NULL));

//	ps.emit <ZeroParticle> (5);
	ps.emit <SharkParticle> (1);
	ps.emit <SwarmParticle> (50);

	glutInit (&_argc, _argv);
	glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
	glutInitWindowSize (500, 500);

	hwin = glutCreateWindow ("cellsius");

	glutDisplayFunc (display);
	glutKeyboardFunc (keyboard);

	glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
	glPointSize (3.0f);
	glEnable (GL_POINT_SMOOTH);

	frametimer (0);
	glutMainLoop ();

	return -1;
}
